package org.demo.mysql.schema.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.demo.mysql.schema.model.SchemaInfo;

import java.util.List;

/**
 * @Title: SchemaMapper
 * @Description: []
 * @Author lei.cheng
 * @Date 2024/8/19
 */
@Mapper
public interface SchemaMapper extends BaseMapper<SchemaInfo> {

    /** 查看表结构 */
    @Select("SELECT\n" +
            "    TABLE_NAME,\n" +
            "    COLUMN_NAME,\n" +
            "    COLUMN_TYPE,\n" +
            "    DATA_TYPE,\n" +
            "    CHARACTER_MAXIMUM_LENGTH as length,\n" +
            "    IS_NULLABLE as IS_NULLABLE,\n" +
            "    COLUMN_DEFAULT as defaultValue,\n" +
            "    COLUMN_COMMENT as comment\n" +
            "FROM\n" +
            "    INFORMATION_SCHEMA.COLUMNS\n" +
            "WHERE\n" +
            "    table_schema = #{schema}\n" +
            "    and table_name = #{tableName}")
    List<SchemaInfo> get(@Param("schema") String schema, @Param("tableName") String tableName);

    /** 查看所有的表 */
    @Select("show tables")
    List<String> getTables();
}
